var uiWaitOptions = {
    lines: 12, // The number of lines to draw
    length: 5, // The length of each line
    width: 2, // The line thickness
    radius: 7, // The radius of the inner circle
    corners: 1, // Corner roundness (0..1)
    rotate: 0, // The rotation offset
    direction: 1, // 1: clockwise, -1: counterclockwise
    color: '#f1f1f1', // #rgb or #rrggbb or array of colors
    speed: 1, // Rounds per second
    trail: 60, // Afterglow percentage
    shadow: false, // Whether to render a shadow
    hwaccel: false, // Whether to use hardware acceleration
    className: 'spinner', // The CSS class to assign to the spinner
    zIndex: 9999 // The z-index (defaults to 2000000000)
};


/*
 *@Toast Class
 */

var Toast = new function () {
    /*
     * @size {large,small(default)}
     * @width {number}
     * @height {number}
     * @position {top, bottom, center(default)}
     * @type {success, failure, warning}
     * @text {string}
     * @timeout {number | default 2000, custom}
     * @id {string}
     */
    this.IsDialog = false;

    this.show = function (options) {
        //console.log("applicationOs: "+App.applicationOs);
        if (App.applicationOs == "other") {
            UI_Dialog.showConfirm({
                title: "VTVNOW Thông báo",
                content: options.text,
                buttons: [{
                        id: "Confirm_cancel",
                        text: "Đồng ý"
                    }]
            });
        } else {
            var type = "";
            switch (options.type) {
                case "success":
                    type = '<span class="fa fa-check"></span>';
                    break;
                case "failure":
                    type = '<span class="fa fa-frown-o"></span>';
                    break;
                case "warning":
                    type = '<span class="fa fa-exclamation-circle"></span>';
                    break;
                default:
                    break;
            }

            var position = "";
            switch (options.position) {
                case "top":
                    position = 'Toast_message_top ';
                    break;
                case "bottom":
                    position = 'Toast_message_bottom ';
                    break;
                default:
                    position = 'Toast_message_center ';
                    break;
            }

            var height = options.height == undefined ? "" : "height:" + options.height + "px;";
            var width = options.width == undefined ? "" : "width:" + options.width + "px;";
            var size = options.size == "large" ? "Toast_message_large " : "";
            var id = options.id == undefined ? "" : "id = '" + options.id + "'";

            if ($(".Toast_message").length == 0 || $(".Toast_button_load").length > 0) {
                Toast.close();
                $("body").append('<div ' + id + ' style="' + height + width + '" class="Toast_message ' + size + position + '"><div class="Toast_message_inner">' + type + options.text + '</div></div>');
            }

            var timeout = options.timeout == undefined ? 2000 : options.timeout;

            if (timeout != "custom") {
                setTimeout(function () {
                    var id = options.id == undefined ? "" : options.id;
                    $("#" + id).remove();
                }, timeout);
            }
        }

    };

    this.button = function (options) {
        this.show(options);
        $(".Toast_message_inner").UI_AddClassHover("hover");
        $(".Toast_message_inner").off("tap").addClass("Toast_button");
        $(".Toast_message_inner").on("tap", function () {
            if (typeof options.click == 'function') {
                options.click();
            }
        });
    };

    this.buttonLoad = function (text) {
        $(".Toast_button").addClass("Toast_button_load").html('<span class="toast_preload"></span> ' + text).removeClass("Toast_button");
    };

    this.close = function (id) {
        $(".Toast_message").remove();
    };

    /*
     * @width {number}
     * @height {number}
     * @mode {icon(default), icon-text}
     * @type {success, loading(default), failure, warning}
     * @text {string}
     */
    this.progress = function (options) {

        // if (!new Popup().isOpen() || Infobar.is_show()) {
        var mode = "";
        var text = "";
        if (options.text != undefined) {
            mode = 'Toast_proccess_text';
            text = options.text;
        }
        var turnoff = options.turnoff == undefined ? false : options.turnoff;
        var type = "";
        switch (options.type) {
            case "success":
                type = '<span class="fa fa-check"></span>' + text;
                break;
            case "failure":
                type = '<span class="fa fa-frown-o"></span>' + text;
                break;
            case "warning":
                type = '<span class="fa fa-exclamation-circle"></span>' + text;
                break;
            default:
                type = '<span class="toast_preload"></span>' + text;
                break;
        }

        var height = options.height == undefined ? "" : "height:" + options.height + "px;";
        var width = options.width == undefined ? "" : "width:" + options.width + "px;";
        var class_effect = options.effect == undefined ? "" : options.effect;
        var html = '<div class="Toast_proccess_wrapper">\n\
                        <div style="' + width + height + '" class="Toast_proccess ' + mode + ' ' + class_effect + '">' + type + '</div></div>';
        $("body").append(html).css({overflow: "hidden"});

//        $(".Toast_proccess").on("tap", function () {
//            $(".Toast_proccess_wrapper").remove();
//            $("body").css({overflow: "auto"});
//        });

        if (turnoff != false) {
            setTimeout(function () {
                if (options.effect != undefined) {
                    $(".Toast_proccess").removeClass("rollIn").addClass("rollOut");
                    setTimeout(function () {
                        $(".Toast_proccess_wrapper").remove();
                        $("body").css({overflow: "auto"});
                    }, 400);
                } else {
                    $(".Toast_proccess_wrapper").remove();
                    $("body").css({overflow: "auto"});
                }

            }, turnoff);
        }
        //}
    };

    /*
     * @type {success(default), failure, warning}
     * @text {string}
     * @turnoff {number | default 1200}
     */
    this.progressNext = function (options) {

        if (options == undefined) {
            $(".Toast_proccess_wrapper").remove();
            $("body").css({overflow: "auto"});
            //$("body").removeClass("toasting");
        } else {
            var height = options.height == undefined ? "" : "height:" + options.height + "px;";
            var width = options.width == undefined ? "" : "width:" + options.width + "px;";
            var turnoff = options.turnoff == undefined ? false : options.turnoff;
            var type = "";
            var text = options.text == undefined ? "" : options.text;
            switch (options.type) {
                case "preload":
                    type = '<span class="toast_preload"></span>' + text;
                    break;
                case "success":
                    type = '<span class="fa fa-check"></span>' + text;
                    break;
                case "failure":
                    type = '<span class="fa fa-frown-o"></span>' + text;
                    break;
                case "warning":
                    type = '<span class="fa fa-exclamation-circle"></span>' + text;
                    break;
                default:
                    type = '<span class="fa fa-check"></span>' + text;
                    break;
            }

            $(".Toast_proccess").html(type).attr("style", width + height);
            $(".Toast_proccess").on("tap", function () {
                $(".Toast_proccess_wrapper").remove();
                $(".Toast_proccess").off("tap");
            });
            if (turnoff != false) {
                setTimeout(function () {
                    $(".Toast_proccess_wrapper").remove();
                }, turnoff);
            }
        }
    };

    this.progressNextToToast = function (options) {
        $(".Toast_proccess_wrapper").remove();
        this.show(options);
    };
};

